package com.example.administrator.damaiwang.Activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.administrator.damaiwang.R;
import com.example.administrator.damaiwang.fragment.Fragment_faxian;
import com.example.administrator.damaiwang.fragment.Fragment_tuijian;
import com.example.administrator.damaiwang.fragment.Fragment_wode;
import com.example.administrator.damaiwang.fragment.Fragment_yanchu;

public class MainActivity extends AppCompatActivity {

    private RadioGroup rg;
    private RadioButton tuijian;
    private RadioButton yanchu;
    private RadioButton faxian;
    private RadioButton wode;
    private LinearLayout ll;
    private FragmentTransaction transaction;
    private FragmentManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rg = (RadioGroup) findViewById(R.id.rg);
        tuijian = (RadioButton) findViewById(R.id.tuijian);
        yanchu = (RadioButton) findViewById(R.id.yanchu);
        faxian = (RadioButton) findViewById(R.id.faxian);
        wode = (RadioButton) findViewById(R.id.wode);
        ll = (LinearLayout) findViewById(R.id.ll);
//        final Fragment_tuijian ftuijian = new Fragment_tuijian();
//        final Fragment_yanchu fyanchu = new Fragment_yanchu();
//        final Fragment_faxian ffaxian = new Fragment_faxian();
//        final Fragment_wode fwode = new Fragment_wode();
        manager = getSupportFragmentManager();
        manager.beginTransaction().add(R.id.ll,new Fragment_tuijian()).commit();

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction transaction = manager.beginTransaction();
                switch (checkedId){
                    case R.id.tuijian:
                        transaction.replace(R.id.ll,new Fragment_tuijian());
                        break;
                    case R.id.yanchu:
                        transaction.replace(R.id.ll,new Fragment_yanchu());
                        break;
                    case R.id.faxian:
                        transaction.replace(R.id.ll,new Fragment_faxian());
                        break;
                    case R.id.wode:
                        transaction.replace(R.id.ll,new Fragment_wode());
                        break;
                }
                transaction.commit();
            }
        });
    }
}
